<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>前后端命名最佳实践 | 前端一锅煮</title>
    <meta name="description" content="前后端命名最佳实践">
    <link rel="icon" href="/blog/logo.jpg">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="msapplication-TileColor" content="#000000">
    <meta name="keywords" content="前端一锅煮,前后端命名最佳实践">
    <link rel="preload" href="/blog/assets/css/0.styles.3a36f1f3.css" as="style"><link rel="preload" href="/blog/assets/js/app.2d50d9dc.js" as="script"><link rel="preload" href="/blog/assets/js/22.d2fad5dd.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.cf06b472.js"><link rel="prefetch" href="/blog/assets/js/11.57a175c6.js"><link rel="prefetch" href="/blog/assets/js/12.b32f2db2.js"><link rel="prefetch" href="/blog/assets/js/13.818a88b3.js"><link rel="prefetch" href="/blog/assets/js/14.1c54dd87.js"><link rel="prefetch" href="/blog/assets/js/15.40ea867f.js"><link rel="prefetch" href="/blog/assets/js/16.379721e3.js"><link rel="prefetch" href="/blog/assets/js/17.0b8bcd15.js"><link rel="prefetch" href="/blog/assets/js/18.41bb3889.js"><link rel="prefetch" href="/blog/assets/js/19.6362af40.js"><link rel="prefetch" href="/blog/assets/js/2.55dfcea5.js"><link rel="prefetch" href="/blog/assets/js/20.4ce40a8a.js"><link rel="prefetch" href="/blog/assets/js/21.ba4dcc65.js"><link rel="prefetch" href="/blog/assets/js/23.2a976f6d.js"><link rel="prefetch" href="/blog/assets/js/24.a6407b77.js"><link rel="prefetch" href="/blog/assets/js/25.28818591.js"><link rel="prefetch" href="/blog/assets/js/26.a4d6759f.js"><link rel="prefetch" href="/blog/assets/js/27.fe72fdf4.js"><link rel="prefetch" href="/blog/assets/js/28.ca4a85a9.js"><link rel="prefetch" href="/blog/assets/js/29.4c6c0c28.js"><link rel="prefetch" href="/blog/assets/js/3.e235257b.js"><link rel="prefetch" href="/blog/assets/js/30.6aa9a972.js"><link rel="prefetch" href="/blog/assets/js/31.b7bccc14.js"><link rel="prefetch" href="/blog/assets/js/32.3544b6a6.js"><link rel="prefetch" href="/blog/assets/js/33.3bb697fd.js"><link rel="prefetch" href="/blog/assets/js/34.ac7cecf3.js"><link rel="prefetch" href="/blog/assets/js/35.b26fe96f.js"><link rel="prefetch" href="/blog/assets/js/36.91eb88f8.js"><link rel="prefetch" href="/blog/assets/js/37.baa3c248.js"><link rel="prefetch" href="/blog/assets/js/4.04108111.js"><link rel="prefetch" href="/blog/assets/js/5.2e3bc3e6.js"><link rel="prefetch" href="/blog/assets/js/6.88208dc4.js"><link rel="prefetch" href="/blog/assets/js/7.7913f494.js"><link rel="prefetch" href="/blog/assets/js/8.64ff3aa5.js"><link rel="prefetch" href="/blog/assets/js/9.43d70a25.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.3a36f1f3.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><!----> <span class="site-name">前端一锅煮</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link">首页</a></div><div class="nav-item"><a href="/blog/page/list/" class="nav-link router-link-active">全部文章</a></div><div class="nav-item"><a href="/blog/page/vuepress/" class="nav-link">VuePress笔记</a></div><div class="nav-item"><a href="/blog/page/about/" class="nav-link">关于我</a></div> <a href="https://gitee.com/cjm0/blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    Gitee
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link">首页</a></div><div class="nav-item"><a href="/blog/page/list/" class="nav-link router-link-active">全部文章</a></div><div class="nav-item"><a href="/blog/page/vuepress/" class="nav-link">VuePress笔记</a></div><div class="nav-item"><a href="/blog/page/about/" class="nav-link">关于我</a></div> <a href="https://gitee.com/cjm0/blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    Gitee
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>前后端命名最佳实践</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/blog/page/list/fe_server_name.html#命名规范" class="sidebar-link">命名规范</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/page/list/fe_server_name.html#最佳实践" class="sidebar-link">最佳实践</a></li><li class="sidebar-sub-header"><a href="/blog/page/list/fe_server_name.html#原因分析" class="sidebar-link">原因分析</a></li></ul></li><li><a href="/blog/page/list/fe_server_name.html#项目交付标准" class="sidebar-link">项目交付标准</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/page/list/fe_server_name.html#低级" class="sidebar-link">低级</a></li><li class="sidebar-sub-header"><a href="/blog/page/list/fe_server_name.html#合格" class="sidebar-link">合格</a></li><li class="sidebar-sub-header"><a href="/blog/page/list/fe_server_name.html#标准" class="sidebar-link">标准</a></li></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="前后端命名最佳实践"><a href="#前后端命名最佳实践" class="header-anchor">#</a> 前后端命名最佳实践</h1> <h2 id="命名规范"><a href="#命名规范" class="header-anchor">#</a> 命名规范</h2> <h3 id="最佳实践"><a href="#最佳实践" class="header-anchor">#</a> 最佳实践</h3> <p>命名是个困扰了我很久的问题，各种方式都试过，现在总结固化一下作为一个大结论。</p> <p>原则：优先考虑小写、下划线，不用中划线。</p> <p><strong>1. 文件夹 小写 下划线</strong></p> <p><strong>2. 文件名 小写 下划线</strong></p> <p><strong>3. 样式名 小写 下划线</strong></p> <p><strong>4. 类名 首字母大写 驼峰</strong></p> <p><strong>5. 函数名 驼峰</strong></p> <p><strong>6. 变量名 驼峰</strong></p> <p><strong>7. 常量名 全大写 下划线</strong></p> <p><strong>8. 数据库名 小写 下划线</strong></p> <p><strong>9. 数据库表 小写 下划线</strong></p> <p><strong>10. 字段名 小写 下划线</strong></p> <h3 id="原因分析"><a href="#原因分析" class="header-anchor">#</a> 原因分析</h3> <h4 id="用小写原因"><a href="#用小写原因" class="header-anchor">#</a> 用小写原因</h4> <ol><li><p>Linux 系统是大小写敏感的，而 Windows 系统和 Mac 系统大小写不敏感</p></li> <li><p>某些系统（Ubuntu）的用户目录首字母大写（早期 Unix 系统 ls 大写的排前面），便于区分</p></li> <li><p>易读、易写</p></li></ol> <h4 id="用下划线原因"><a href="#用下划线原因" class="header-anchor">#</a> 用下划线原因</h4> <ol><li><p>样式中使用容易复制，点击一次即可选中</p></li> <li><p>变量不支持中划线，支持下划线</p></li> <li><p>全部统一成下划线，省事省心</p></li></ol> <h2 id="项目交付标准"><a href="#项目交付标准" class="header-anchor">#</a> 项目交付标准</h2> <h3 id="低级"><a href="#低级" class="header-anchor">#</a> 低级</h3> <p>实现全部功能需求</p> <p>解决全部 bug</p> <h3 id="合格"><a href="#合格" class="header-anchor">#</a> 合格</h3> <p>实现全部功能需求</p> <p>解决全部 bug</p> <p>代码格式统一(eslint 检测)、命名规范统一、极其详细的注释，代码合理的封装、隔离</p> <p>走完前端上线必检清单，走完后端上线必检清单</p> <p>需求文档、设计图、前端说明文档、后端接口文档、测试报告齐全</p> <h3 id="标准"><a href="#标准" class="header-anchor">#</a> 标准</h3> <p>实现全部功能需求</p> <p>解决全部 bug</p> <p>代码格式统一(eslint 检测)、命名规范统一、极其详细的注释，代码合理的封装、隔离</p> <p>走完前端上线必检清单，走完后端上线必检清单</p> <p>需求文档、设计图、前端说明文档、后端接口文档、测试报告齐全</p> <p>后端接口单元测试报告、后端接口压力测试报告、运维部署说明</p></div> <div class="page-edit"><div class="edit-link"><a href="https://gitee.com/cjm0/blog/edit/master/docs/page/list/fe_server_name.md" target="_blank" rel="noopener noreferrer">在 Gitee 上编辑此页</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <!----></div> <!----> </div> <!----></div></div>
    <script src="/blog/assets/js/app.2d50d9dc.js" defer></script><script src="/blog/assets/js/22.d2fad5dd.js" defer></script>
  </body>
</html>
